package cn.edu.cqut.controller;


import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.cqut.entity.Customer;
import cn.edu.cqut.entity.Plan;
import cn.edu.cqut.service.IPlanService;
import cn.edu.cqut.util.PageResult;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cqut-917371
 * @since 2020-06-24
 */
@RestController
@RequestMapping("/plan")
@CrossOrigin  //允许跨域请求
public class PlanController {
	@Autowired
	private IPlanService planService;
	@RequestMapping("/addPlan")
	public PageResult<Plan> addCustomer(Plan plan){
		planService.save(plan);
		PageResult<Plan> pr = new PageResult<>();
		pr.setCode(0);
		pr.setMsg("新增客户信息成功");
		return pr;
	}
//	@RequestMapping("/developSuccess")
//	public PageResult<Plan> delCustomer(@RequestBody List<Plan> plans){
//		for(Plan pl:plans) {
//			planService.updateById(pl);
//		}
//		planService.updateBatchById(plans);
//		PageResult<Plan> pr = new PageResult<>();
//		pr.setCode(0);
//		pr.setMsg("开发成功");
//		return pr;
//	}
	
	//开发成功
	@RequestMapping("/developSuccess")
	public PageResult<Plan> developSuccess(Plan plan){
		planService.updateById(plan);
		PageResult<Plan> pr = new PageResult<>();
		pr.setCode(0);
		pr.setMsg("开发成功");
		return pr;
	}
	//开发失败
		@RequestMapping("/developFail")
		public PageResult<Plan> developFail(Plan plan){
			planService.updateById(plan);
			PageResult<Plan> pr = new PageResult<>();
			pr.setCode(0);
			pr.setMsg("开发失败");
			return pr;
		}
	//编辑开发计划
		@RequestMapping("/editPlan")
		public PageResult<Plan> editPlan(Plan plan){
			planService.updateById(plan);
			PageResult<Plan> pr = new PageResult<>();
			pr.setCode(0);
			pr.setMsg("开发失败");
			return pr;
		}
	}


